package 线程安全.多线程.单线程;

import java.io.*;
import java.net.Socket;
import java.util.Scanner;

public class Client {
    public static void main(String[] args) throws IOException {
        Socket socket = new Socket("127.0.0.1", 12306);
        Scanner sc = new Scanner(System.in);
        while (true) {
            System.out.print("我: ");
            String str = sc.nextLine();

            BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
            bw.write(str + "\r\n");
            bw.flush();

            BufferedReader br = new BufferedReader(new InputStreamReader(socket.getInputStream()));
            String s = br.readLine();
            System.out.println("王杰: " + s);

//            socket.close();
        }


    }
}
